<?php
$fbconfig = array(
                'appId'=>  Yii::app()->params['facebookApi'],
                'secret'=> Yii::app()->params['facebookSecretCode'],
                'domain'=> Yii::app()->params['facebookDomain'],
                'status'=> Yii::app()->params['facebookStatus'],
                'xfbml'=>  Yii::app()->params['xfbml'],
                'cookie'=> Yii::app()->params['facebookCookie'],
                'lang'=>   Yii::app()->params['facebookLang'],
        );
if(isset($fbconfig)) {
	require_once('../facebook-php-sdk/src/facebook.php');
    	$facebook = new Facebook($fbconfig);
	$user = $facebook->getUser();
	if($user != 0){
		$params = array(
				'next' =>'http://www.'.$fbconfig['domain'].$this->createUrl('site/logout'),  
				);
		$fb_logout = $facebook->getLogoutUrl($params);
	}
    	if($user && Yii::app()->user->isGuest && $fb_logout)
		if($this->action->id == 'login' ){
			Yii::app()->session['uid'] = $user;
			Yii::app()->session['logout'] = $fb_logout;
			$this->redirect($this->createUrl('site/Fblogin'));
		}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pt_BR" lang="pt_BR" xmlns:fb="http://www.facebook.com/2008/fbml">
    <head>
	<meta content="ROANAVi - Repositório de Objetos de Aprendizagem do NAV" name="description"/>
	<meta content="Isaac Marinho" name="author"/>
	<meta content="Objetos de Aprendizagem, OAs, Aprendizagem, EaD, NAV, Aprendizagem Virtual" name="keywords"/>
	<meta content="ROANAVi - Repositório de Objetos de Aprendizagem do NAV" property="og:title"/>
	<meta content="website" property="og:type"/>
	<meta content="http://www.nav.ifpb.edu.br/roanavi-beta/" property="og:url"/>
	<meta content="http://open.thumbshots.org/image.aspx?url=www.nav.ifpb.edu.br/roanavi-beta" property="og:image"/>
	<meta content="ROANAVi" property="og:site_name"/>
	<meta content="178038878920876" property="fb:app_id"/>
	<meta content="1098100447" property="fb:admins"/>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta name="language" content="pt_BR" />

        <!-- blueprint CSS framework -->
        <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/screen.css" media="screen, projection" />
        <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/print.css" media="print" />
        <!--[if lt IE 8]>
	<link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/ie.css" media="screen, projection" />
	<![endif]-->
	<link rel="shortcut icon" href="<?php echo Yii::app()->request->baseUrl; ?>/assets/images/favicon.ico" type="image/x-icon" />
        <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/main.css" />
        <link rel="stylesheet" type="text/css" href="<?php echo Yii::app()->request->baseUrl; ?>/css/form.css" />

        <title><?php echo CHtml::encode($this->pageTitle); ?></title>
    </head>

    <body>
<?php if(isset($fbconfig)): ?>
<div id="fb-root"></div>
      <script>
	window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo $facebook->getAppID() ?>',
          cookie: true,
          xfbml: true,
          oauth: true
        });
        FB.Event.subscribe('auth.login', function(response) {
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });
      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/<?php echo $fbconfig['lang']; ?>/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());	
</script>
<?php endif; ?>

        <div class="container" id="page">
<?php 
$src = Yii::app()->request->baseUrl.Yii::app()->params['logo'];
$alt = Yii::app()->name;
$htmlOptions=array ( );
?>	
            <div id="header">
		<!--<div id="logo"><?php //echo  CHtml::image($src, $alt, $htmlOptions) ?></div>-->
		<div id="title"><?php echo CHtml::encode(Yii::app()->name); ?> <sup style="font-size: 55%">beta</sup></div>
            </div><!-- header -->

            <div id="mainmenu">
                <?php
		$username = array();
		$username = (Yii::app()->user->getState('fbname'))?array(Yii::app()->user->getState('fbname')): explode('@',Yii::app()->user->name,2);

                $this->widget('zii.widgets.CMenu', array(
                    'items' => array(
                        array('label' => 'Home', 'url' => array('/site/index')),
			array('label' => 'Autores', 'url'=>array('/autor/index'), 'visible' =>!Yii::app()->user->isGuest),
			array('label' => 'Áreas de Conhecimento', 'url'=>array('/areaConhecimento/index'), 'visible' =>!Yii::app()->user->isGuest),
			array('label' => 'Tipos de OAs', 'url'=>array('/tipoOA/index'), 'visible' =>!Yii::app()->user->isGuest),
			array('label' => 'Níveis de Ensino', 'url'=>array('/nivelEnsino/index'), 'visible' =>((!Yii::app()->user->isGuest) && (Yii::app()->user->getState('role') == Yii::app()->params['admin']))),
			array('label' => 'Objetos de Aprendizagem', 'url'=>array('/oA/index'), 'visible' =>!Yii::app()->user->isGuest),
			array('label' => 'Avaliações de OAs', 'url'=>array('/avaliacaoOA/index'), 'visible' =>!Yii::app()->user->isGuest),
			array('label' => 'Usuários', 'url'=>array('/usuario/index'), 'visible' => ((!Yii::app()->user->isGuest) && (Yii::app()->user->getState('role') == Yii::app()->params['admin']))),
                        array('label' => 'Sobre', 'url' => array('/site/page', 'view' => 'about')),
                        array('label' => 'Contato', 'url' => array('/site/contact')),
                        array('label' => 'Login', 'url' => array('/site/login'), 'visible' => Yii::app()->user->isGuest),
		
	                array('label' => 'Sair (' . ucfirst( utf8_decode( $username[0] ) ) . ')', 'url' => array('/site/logout'), 'visible' => !Yii::app()->user->isGuest)
                    ),
                ));  
		//echo Yii::app()->session['logout'];  
		//echo '<br/>';
		//print_r($fb_session);	         
		?>  
            </div><!-- mainmenu -->
            <?php if (isset($this->breadcrumbs)): ?>
                <?php
                $this->widget('zii.widgets.CBreadcrumbs', array(
                    'links' => $this->breadcrumbs,
                ));
                ?><!-- breadcrumbs -->
            <?php endif ?>


            <?php echo $content; ?>

            <div id="footer">
		Copyright &copy; <?php echo date('Y'); ?> by <? echo CHtml::link('NAV','http://www.nav.ifpb.edu.br', array('title' => 'Site do NAV', 'target' => '_blank')); ?>.<br/>
		All Rights Reserved.<br/>
                <?php echo Yii::powered(); ?>
            </div><!-- footer -->

        </div><!-- page -->
    </body>
</html>
